package com.entities.projectversion.servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.core.protocols.IServiceLayerDelegate;
import com.core.servlets.TaskTrackerServlet;
import com.core.utils.GlobalConstants;
import com.entities.projectversion.servicelayer.VersionListLayer;

public class VersionDelete
        extends TaskTrackerServlet
        implements IServiceLayerDelegate {

	private HttpServletResponse postResponse = null;



	@Override
	public <T> void responseResponseItemsList ( final List <T> items,
	                                            final Object request,
	                                            final Exception exception ) {

		if ( postResponse == null ) {
			return;
		}

		if ( exception != null ) {

		}

		String redirection = null;
		redirection = String.format("%s", GlobalConstants.SERVLET_PROJECTLIST);

		if ( this.postResponse != null ) {
			try {
				this.postResponse.sendRedirect(redirection);
			} catch ( IOException e ) {
				e.printStackTrace();
			}
		}

	}

	private static final long serialVersionUID = 1L;



	@Override
	protected void doPost ( HttpServletRequest request,
	                        HttpServletResponse response )
	        throws ServletException, IOException {

		this.postResponse = response;

		String versionId = request.getParameter(GlobalConstants.SERVLET_PARAM_KEY);
		Integer objectId = null;
		try{
			objectId = Integer.parseInt(versionId);
		}catch(NumberFormatException e){
			objectId = null;
		}

		VersionListLayer versionListLayer = new VersionListLayer();
		versionListLayer.setLayerDelegate(this);
		versionListLayer.deleteObject(objectId);

	}



}
